/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package co.gov.igac.observatorio.beans.navegacion;

import javax.inject.Named;
import javax.enterprise.context.SessionScoped;
import java.io.Serializable;
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpSession;

/**
 *
 * @author jgamba
 */
@Named(value = "navegacionBean")
@SessionScoped
public class NavegacionBean implements Serializable {

    /** Creates a new instance of NavegacionBean */
    public NavegacionBean() {
    }
    private String includedPage = "./plantilla/inicio.xhtml";

    public String navegar() {

        FacesContext context = FacesContext.getCurrentInstance();
        String selectedPageViewId =
                context.getExternalContext().getRequestParameterMap().get("paginaSolicitada");
        //resetearBeans(context);
        if (selectedPageViewId.equalsIgnoreCase("FI")) {
            includedPage = "/ideaInvestigacion/idea/FormularIdea.xhtml";
        } else if (selectedPageViewId.equalsIgnoreCase("EI")) {
            includedPage = "/ideaInvestigacion/idea/EditarIdea.xhtml";
        } else if (selectedPageViewId.equalsIgnoreCase("RI")) {
            includedPage = "/observatorio/investigador/RegistrarInvestigador.xhtml";
        } else if (selectedPageViewId.equalsIgnoreCase("RE")) {
            includedPage = "/observatorio/entidad/RegistrarEntidad.xhtml";
        } else if (selectedPageViewId.equalsIgnoreCase("CP")) {
            includedPage = "/observatorio/proyecto/CrearProyecto.xhtml";
        } else if (selectedPageViewId.equalsIgnoreCase("FP")) {
            includedPage = "/propuestaInvestigacion/propuesta/FormularPropuesta.xhtml";
        } else if (selectedPageViewId.equalsIgnoreCase("ejemplo2")) {
            includedPage = "/plantilla/inicio_2.xhtml";
        } else if (selectedPageViewId.equalsIgnoreCase("test")) {
            includedPage = "/ideaInvestigacion/idea/prueba.xhtml";
        }else if (selectedPageViewId.equalsIgnoreCase("nodisp")) {
            includedPage = "/ideaInvestigacion/idea/nodisp.xhtml";
        }else if (selectedPageViewId.equalsIgnoreCase("consulta")) {
            includedPage = "/ideaInvestigacion/idea/consulta.xhtml";
        }else if (selectedPageViewId.equalsIgnoreCase("CE")) {
            includedPage = "/observatorio/consultas/entidad/ConsultasEntidad.xhtml";
        }else if (selectedPageViewId.equalsIgnoreCase("INI")) {
            includedPage = "/plantilla/inicio.xhtml";
        }else if (selectedPageViewId.equalsIgnoreCase("CI")) {
            includedPage = "/observatorio/consultas/investigador/ConsultasInvestigador.xhtml";
        }else if (selectedPageViewId.equalsIgnoreCase("CPr")) {
            includedPage = "/observatorio/consultas/proyecto/ConsultasProyecto.xhtml";
        }else if (selectedPageViewId.equalsIgnoreCase("CB")) {
            includedPage = "/observatorio/consultas/idea/ConsultasIdeas.xhtml";
        }
        return "";
    }

    public void resetearBeans(FacesContext context) {
        // para mantener al usuario en session todo el tiempo.

        HttpSession session = (HttpSession) context.getExternalContext().getSession(false);

        for (String val : session.getValueNames()) {
            if (!val.equals("PageViewIdGenerator") && !val.equals("loginBean")) {
                System.out.println(val);
                session.removeValue(val);
            }
        }

    }

    /**
     * @return the includedPage
     */
    public String getIncludedPage() {
        return includedPage;
    }

    /**
     * @param includedPage the includedPage to set
     */
    public void setIncludedPage(String includedPage) {
        this.includedPage = includedPage;
    }

    
}
